package goods

import (
	"context"
	"test-demo/goods_srv/goods"

	"test-demo/api/internal/svc"
	"test-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DownGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDownGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownGoodsLogic {
	return &DownGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DownGoodsLogic) DownGoods(req *types.DownGoodsReq) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.GoodsServer.DownGoods(context.Background(), &goods.DownGoodsReq{
		Userid:  int64(req.Userid),
		Goodsid: int64(req.Goodsid),
	})
	if res.Pong == "0" {
		return &types.Response{
			Code:    10001,
			Message: "商品下架失败",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品下架成功",
		Data:    nil,
	}, nil
}
